package com.yxjx.duoxue;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * SHA1加密
 * 
 * @author zhangxs
 * @date 2012-1-5
 * 
 */
public class EncryptGenSHA1 {

    /**
     * 加密
     * 
     * @param strSrc
     * @return
     */
    public static String Encrypt(String strSrc) {
        String strDes = "";

        byte[] bt = strSrc.getBytes();
        try {
            MessageDigest md = MessageDigest.getInstance("SHA-1");
            md.update(bt);
            strDes = EncryptCommon.parseByte2HexStr(md.digest());
        } catch (NoSuchAlgorithmException e) {
            System.out.println("Invalid algorithm.");
            return "";
        }

        return strDes;
    }

        public static void main(String[] args) {
            String strSrc = "sqtxj5dn2kwtikwu";
            String pwd = "123456";
            
            System.out.println("Source String:" + strSrc);
    
            String ss = EncryptGenSHA1.Encrypt(pwd+strSrc).toUpperCase();
            System.out.println(ss);
            System.out.println(ss.length());
        }

}
